package com.xingzhe.pengji.security.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ColumnResult;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;

import com.xingzhe.pengji.util.SqlUtil;

@Entity
@Table(name = "PJT_AUTHORITIES")
@NamedNativeQueries(value = {
        @NamedNativeQuery(name =  SqlUtil.NAME_GET_AUTHORITIE_NAME_BY_USER_ACCOUNT, query = SqlUtil.SQL_GET_AUTHORITIE_NAME_BY_USER_ACCOUNT, resultSetMapping = SqlUtil.RSM_GET_AUTHORITIE_NAME_BY_USER_ACCOUNT),
        @NamedNativeQuery(name=SqlUtil.NAME_GET_ALL_AUTHORITIES_NAME,query=SqlUtil.SQL_GET_ALL_AUTHORITIES_NAME,resultSetMapping =SqlUtil.RSM_GET_ALL_AUTHORITIES_NAME)
})
@SqlResultSetMappings(value={
        @SqlResultSetMapping(name=SqlUtil.RSM_GET_AUTHORITIE_NAME_BY_USER_ACCOUNT,columns={@ColumnResult(name="AUTHORITIES_NAME")}),
        @SqlResultSetMapping(name=SqlUtil.RSM_GET_ALL_AUTHORITIES_NAME,columns={@ColumnResult(name="AUTHORITIES_NAME")})
})

public class Authoritie  implements Serializable {

	private static final long serialVersionUID = -67855477244626524L;

	@Id
	@Column(length=36,nullable=false)
	@GeneratedValue(generator = "generator")
	@GenericGenerator(name = "generator", strategy = SqlUtil.HIBERNATE_UUID)
	private String id;

	@Column(name = "NAME", unique = true, length = 20, nullable = false)
	private String name;

	@Column(name = "DESCRIPTION", length = 100)
	private String description;

	@Column(name = "ENABLED", nullable = false)
	private int enabled;

    @Column(name = "IS_SYS", nullable = false)
    private int isSys;

	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "PJT_GROUPS_AUTHORITIES", joinColumns = { @JoinColumn(name = "AUTHORITIE_ID") }, inverseJoinColumns = { @JoinColumn(name = "GROUP_ID") })
	private List<Group> listGroups = new ArrayList<Group>();

	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "PJT_RESOURCES_AUTHORITIES", joinColumns = { @JoinColumn(name = "AUTHORITIE_ID") }, inverseJoinColumns = { @JoinColumn(name = "RESOURCE_ID") })
	private List<Resource> listResources = new ArrayList<Resource>();

	public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getEnabled() {
		return enabled;
	}

	public void setEnabled(int enabled) {
		this.enabled = enabled;
	}

	public int getIsSys() {
		return isSys;
	}

	public void setIsSys(int isSys) {
		this.isSys = isSys;
	}

	public List<Group> getListGroups() {
		return listGroups;
	}

	public void setListGroups(List<Group> listGroups) {
		this.listGroups = listGroups;
	}

	public List<Resource> getListResources() {
		return listResources;
	}

	public void setListResources(List<Resource> listResources) {
		this.listResources = listResources;
	}

}
